package controller.v2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.v2.PayService;
import util.PackageUtil;

@Controller
@RequestMapping("/v2/pay")
public class WechatPayController {
	
	@Autowired
	private PayService payService;
	
	/**
	 * 微信统一下单接口
	 * 
	 * @param request
	 * @param response
	 * @attr param payType 1 余额充值 
	 */
	@ResponseBody
	@RequestMapping("/wxPrePay")																							
	public Object wxPrePay(@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id ,  
			HttpServletRequest request, HttpServletResponse response) {
		if(request.getAttribute("payType")==null){
			return PackageUtil.packageParams(403,"forbidden","",""); 
		}
		int type = (Integer)request.getAttribute("payType");
		String no = 	(String) request.getAttribute("order_no");
		String price = 	(String) request.getAttribute("price");
		String body = 	(String) request.getAttribute("body");
		
		//余额充值
		if(type==1){
			String url = "pay/rechargeWechatPayNotify";
			return payService.wxPrePay(no, price ,body, request,url);
		}else if(type ==2){
			String url = "pay/ticketWechatPayNotify";
			return payService.wxPrePay(no, price ,body, request,url);
		}else if(type ==3){
			String url = "pay/OrderWxPayNotify";
			return payService.wxPrePay(no, price ,body, request,url);
		}else if(type ==4){
			String url = "pay/packageWxPayNotify";
			return payService.wxPrePay(no, price ,body, request,url);
		}
		return null;
	}
}
